package com.itheima04;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author Xiao
 * @date 2021/7/16
 */
public class PrintList {
    /**
     *  List
     *      创建一个存储学生对象的集合，存储3个学生对象，使用程序实现在控制台遍历该集合。
     */
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        Student stu1 = new Student("阿良", 24);
        Student stu2 = new Student("左右", 25);
        Student stu3 = new Student("平安", 21);
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.toString());
        }
        System.out.println("-----------");
        Iterator<Student> it = list.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println("-----------");
        for (Student stu : list) {
            System.out.println(stu.toString());
        }
    }
}
